/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.wlyy.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.yihu.wlyy.entity.follow.FollowUpPlanStage;

public interface FollowUpPlanStageDao extends PagingAndSortingRepository<FollowUpPlanStage, Long>, JpaSpecificationExecutor<FollowUpPlanStage> {

	/**
	 * 根据计划code查询阶段
	 * @param code
	 * @return
	 */
	@Query("select a from FollowUpPlanStage a where a.plan = ?1 order by a.czrq desc")
	List<FollowUpPlanStage> findByPlanCode(String code);

	List<FollowUpPlanStage> findByPlan(String plan);

	FollowUpPlanStage findByCode(String code);

	@Modifying
	@Query("update FollowUpPlanStage a set a.status = ?1 where a.plan = ?2")
	int updateStatusByPlan(int status, String plan);
	
	@Query("select a from FollowUpPlanStage a where a.plan = ?1 and a.seq = ?2")
	FollowUpPlanStage findNextStage(String plan, int seq);
}
